package com.lzx.indicatordemo.demo;

import android.graphics.Color;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.framework.view.indicator.GodIndicator;
import com.framework.view.indicator.GodIndicatorAdapter;
import com.framework.view.indicator.indicators.configs.LineIndicatorConfig;
import com.framework.view.indicator.model.IndicatorShapeType;
import com.framework.view.indicator.model.IndicatorWidthModel;
import com.framework.view.indicator.configs.TextTitleConfig;
import com.lzx.indicatordemo.Constants;
import com.lzx.indicatordemo.ExamplePagerAdapter;
import com.lzx.indicatordemo.R;

import java.util.Arrays;
import java.util.List;

import static com.lzx.indicatordemo.Constants.CHANNELS;

/**
 * description
 *
 * @author liangzx
 * @version 1.0
 * @time 2019-12-23 10:53
 **/
public class TitleFollowSlideDemoActivity extends AppCompatActivity {

    private List<String> mDataList = Arrays.asList(CHANNELS);
    private ViewPager mViewPager;
    private ExamplePagerAdapter mExamplePagerAdapter = new ExamplePagerAdapter(mDataList);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.title_follow_slide_demo_activity);

        mViewPager = findViewById(R.id.vp);
        mViewPager.setAdapter(mExamplePagerAdapter);
        init1();
        init2();
        init3();
        init4();
        init5();
    }

    private void init1() {
        GodIndicator godIndicator = findViewById(R.id.g1);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.BLACK)
                        .setSelectedColor(Color.WHITE)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setWidthModel(IndicatorWidthModel.MATCH_EDGE)
                        .setColors(Constants.indicatorColors)
                        .setShapeType(IndicatorShapeType.ROUND_RECT)
                        .setPendingLeft(10)
                        .setPendingBottom(5)
                        .setRoundRadius(10)
                        .setPendingRight(10);
            }

        });
    }

    private void init2() {
        GodIndicator godIndicator = findViewById(R.id.g2);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.BLACK)
                        .setSelectedColor(Color.WHITE)
                        .setUseColorClip(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setWidthModel(IndicatorWidthModel.MATCH_EDGE)
                        .setColor(Constants.selectedTxtColor)
                        .setShapeType(IndicatorShapeType.ROUND_RECT)
                        .setPendingLeft(10)
                        .setPendingTop(5)
                        .setRoundRadius(10)
                        .setPendingRight(10);
            }

        });
    }

    private void init3() {
        GodIndicator godIndicator = findViewById(R.id.g3);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.BLACK)
                        .setSelectedColors(Constants.selectedTxtColors)
                        .setUseColorClip(true)
                        .setSizeFollowSlideChange(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setWidthModel(IndicatorWidthModel.MATCH_EDGE)
                        .setColor(Constants.selectedTxtColor)
                        .setShapeType(IndicatorShapeType.ROUND_RECT)
                        .setPendingLeft(10)
                        .setPendingTop(5)
                        .setRoundRadius(10)
                        .setPendingRight(10);
            }

        });
    }

    private void init4() {
        GodIndicator godIndicator = findViewById(R.id.g4);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.BLACK)
                        .setSelectedColors(Constants.selectedTxtColors)
                        .setColorGradientFollowSlide(true)
                        .setSizeFollowSlideChange(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setWidthModel(IndicatorWidthModel.MATCH_EDGE)
                        .setColor(Constants.selectedTxtColor)
                        .setShapeType(IndicatorShapeType.ROUND_RECT)
                        .setPendingLeft(10)
                        .setPendingTop(5)
                        .setRoundRadius(10)
                        .setPendingRight(10);
            }

        });
    }

    private void init5() {
        GodIndicator godIndicator = findViewById(R.id.g5);
        godIndicator.setBackgroundColor(Constants.randomBgColor());
        godIndicator.setAdapter(new GodIndicatorAdapter<LineIndicatorConfig>(mViewPager) {
            @Override
            protected TextTitleConfig bindTitleConfig() {
                return TextTitleConfig.factory()
                        .setNormalColor(Color.BLACK)
                        .setSelectedColor(Color.WHITE)
                        .setUseColorClip(true)
                        .setSizeFollowSlideChange(true)
                        .setPendingLeft(20)
                        .setPendingRight(20)
                        .setNormalSize(30)
                        .setSelectedSize(40);
            }

            @Override
            public String getTitleName(int position) {
                return CHANNELS[position];
            }

            @Override
            public int getCount() {
                return CHANNELS.length;
            }

            @Override
            protected LineIndicatorConfig bindIndicatorConfig() {
                return LineIndicatorConfig.factory()
                        .setWidthModel(IndicatorWidthModel.WARP_CONTENT)
                        .setColor(Constants.selectedTxtColor)
                        .setShapeType(IndicatorShapeType.ROUND_RECT)
                        .setRoundRadius(10);
            }

        });
    }

}
